using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class DischargeDispositionAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public DischargeDispositionAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.User;
						tableVersionTypes[HL7Version.v231] = HL7TableType.User;
						tableVersionTypes[HL7Version.v24] = HL7TableType.User;
						tableVersionTypes[HL7Version.v25] = HL7TableType.User;
						tableVersionTypes[HL7Version.v251] = HL7TableType.User;
						tableVersionTypes[HL7Version.v26] = HL7TableType.User;
						tableVersionTypes[HL7Version.v27] = HL7TableType.User;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{""};
						validVersionCodes[HL7Version.v231] = new string[]{"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42"};
						validVersionCodes[HL7Version.v24] = new string[]{"01","02","03","04","05","06","07","08","09","10 ...19","20","21 ... 29","30","31 ... 39","40","41","42"};
						validVersionCodes[HL7Version.v25] = new string[]{"01","02","03","04","05","06","07","08","09","10 ... 19","20","21 ... 29","30","31 ... 39","40","41","42"};
						validVersionCodes[HL7Version.v251] = new string[]{"01","02","03","04","05","06","07","08","09","10 ...19","20","21 ... 29","30","31 ... 39","40","41","42"};
						validVersionCodes[HL7Version.v26] = new string[]{"01","02","03","04","05","06","07","08","09","10 ... 19","20","21 ... 29","30","31 ... 39","40","41","42"};
						validVersionCodes[HL7Version.v27] = new string[]{"…"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{""};
						validVersionDescriptions[HL7Version.v231] = new string[]{"Discharged to home or self care (routine discharge)","Discharged/transferred to another short term general hospital for inpatient care","Discharged/transferred to skilled nursing facility (SNF)","Discharged/transferred to an intermediate care facility (ICF)","Discharged/transferred to another type of institution for inpatient care or referred for outpatient services to another institution","Discharged/transferred to home under care of organized home health service organization","Left against medical advice or discontinued care","Discharged/transferred to home under care of Home IV provider","Admitted as an inpatient to this hospital","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Discharge to be defined at state level, if necessary","Expired","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Expired to be defined at state level, if necessary","Still patient or expected to return for outpatient services","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Still patient to be defined at state level, if necessary","Expired at home","Expired in a medical facility; e.g., hospital, SNF, ICF, or free standing hospice","Expired - place unknown"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"Discharged to home or self care (routine discharge)","Discharged/transferred to another short term general hospital for inpatient care","Discharged/transferred to skilled nursing facility (SNF)","Discharged/transferred to an intermediate care facility (ICF)","Discharged/transferred to another type of institution for inpatient care or referred for outpatient services to another institution","Discharged/transferred to home under care of organized home health service organization","Left against medical advice or discontinued care","Discharged/transferred to home under care of Home IV provider","Admitted as an inpatient to this hospital","Discharge to be defined at state level, if necessary","Expired (i.e. dead)","Expired to be defined at state level, if necessary","Still patient or expected to return for outpatient services (i.e. still a patient)","Still patient to be defined at state level, if necessary  (i.e. still a patient)","Expired (i.e. died) at home","Expired (i.e. died) in a medical facility; e.g., hospital, SNF, ICF, or free standing hospice","Expired (i.e. died)  - place unknown"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"Discharged to home or self care (routine discharge)","Discharged/transferred to another short term general hospital for inpatient care","Discharged/transferred to skilled nursing facility (SNF)","Discharged/transferred to an intermediate care facility (ICF)","Discharged/transferred to another type of institution for inpatient care or referred for outpatient services to another institution","Discharged/transferred to home under care of organized home health service organization","Left against medical advice or discontinued care","Discharged/transferred to home under care of Home IV provider","Admitted as an inpatient to this hospital","Discharge to be defined at state level, if necessary","Expired (i.e. dead)","Expired to be defined at state level, if necessary","Still patient or expected to return for outpatient services (i.e. still a patient)","Still patient to be defined at state level, if necessary  (i.e. still a patient)","Expired (i.e. died) at home","Expired (i.e. died) in a medical facility; e.g., hospital, SNF, ICF, or free standing hospice","Expired (i.e. died)  - place unknown"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"Discharged to home or self care (routine discharge)","Discharged/transferred to another short term general hospital for inpatient care","Discharged/transferred to skilled nursing facility (SNF)","Discharged/transferred to an intermediate care facility (ICF)","Discharged/transferred to another type of institution for inpatient care or referred for outpatient services to another institution","Discharged/transferred to home under care of organized home health service organization","Left against medical advice or discontinued care","Discharged/transferred to home under care of Home IV provider","Admitted as an inpatient to this hospital","Discharge to be defined at state level, if necessary","Expired (i.e. dead)","Expired to be defined at state level, if necessary","Still patient or expected to return for outpatient services (i.e. still a patient)","Still patient to be defined at state level, if necessary  (i.e. still a patient)","Expired (i.e. died) at home","Expired (i.e. died) in a medical facility; e.g., hospital, SNF, ICF, or free standing hospice","Expired (i.e. died)  - place unknown"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Discharged to home or self care (routine discharge)","Discharged/transferred to another short term general hospital for inpatient care","Discharged/transferred to skilled nursing facility (SNF)","Discharged/transferred to an intermediate care facility (ICF)","Discharged/transferred to another type of institution for inpatient care or referred for outpatient services to another institution","Discharged/transferred to home under care of organized home health service organization","Left against medical advice or discontinued care","Discharged/transferred to home under care of Home IV provider","Admitted as an inpatient to this hospital","Discharge to be defined at state level, if necessary","Expired (i.e. dead)","Expired to be defined at state level, if necessary","Still patient or expected to return for outpatient services (i.e. still a patient)","Still patient to be defined at state level, if necessary  (i.e. still a patient)","Expired (i.e. died) at home","Expired (i.e. died) in a medical facility; e.g., hospital, SNF, ICF, or free standing hospice","Expired (i.e. died)  - place unknown"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"no suggested values"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
